﻿@using ThuySan.Areas.Backend.Models
@model ThuySan.Models.CategoryModel
@{
    Layout = "~/Areas/Backend/Views/Shared/_Layout.cshtml";

    Header header = new Header
    {
        Common = "ViewUserControl_Category_Edit",
        CurentCommon = "Category",
        PageHeader = "Edit Category",
        Menulv1 = "01",
        Menulv2 = "0101"
    };
    ViewData[Header.Key] = header;
    ViewBag.Title = "Edit Category - Admin Control Panel";
    Html.EnableClientValidation();
}
<div class="content-box">
    <div class="content-box-header">
        <h3>
            Edit Category</h3>
    </div>
    <div class="content-box-content">
        @using (Html.BeginForm("Edit", "Category", FormMethod.Post, new
        {
            enctype = "multipart/form-data"
        }))
        {
            @Html.ValidationMessage("error")
            @Html.HiddenFor(c => c.CategoryId)
            <div class="input-item">
                <label>
                    Name</label>
                @Html.TextBoxFor(c => c.Name, new
           {
               @class = "text-input medium-input"
           })
                @Html.ValidationMessageFor(c => c.Name)
            </div>
            <div class="input-item">
                <label>
                    Description</label>
                @Html.TextAreaFor(c => c.Description, new
           {
               @class = "text-input large-input"
           })
                @Html.ValidationMessageFor(c => c.Description)
            </div>
            <div class="input-item">
                <label>
                    Detail</label>
                @{
           Html.Telerik().Editor().Name("Detail").Encode(false).HtmlAttributes(new
           {
               style = "height:400px"
           }).Value(Model.Detail).Render();
                }
            </div>
            <div class="input-item">
                <label>
                    Priority</label>
                @Html.TextBoxFor(c => c.Priority, new
           {
               @class = "text-input tiny-input"
           })
                @Html.ValidationMessageFor(c => c.Priority)
            </div>
            <div class="input-item">
                <label>
                    Is Top Menu</label>
                @Html.CheckBoxFor(c => c.IsCategoryMenu)
            </div>
            <div class="title-seperator">
                Page Information</div>
            <div class="seperator">
            </div>
            <div class="input-item">
                <label>
                    Url</label>
                @Html.TextBoxFor(c => c.PageUrl, new
           {
               @class = "text-input medium-input"
           })
                @Html.ValidationMessageFor(c => c.PageUrl)
            </div>
            <input type="submit" value="Update" class="button" />
            <input type="button" onclick="javascript:window.location.href='@Url.Action("Index")';" value="Reset" class="button" />
        }
    </div>
</div>
@{
    Html.Telerik().TabStrip().Name("tabs").Items(c =>
                                                     {
                                                         c.Add().Text("Property").Content(Html.Action("CategoryProperties", new
                                                         {
                                                             id = Model.CategoryId
                                                         }).ToHtmlString());
                                                         c.Add().Text("Option").Content(Html.Action("CategoryTags", new
                                                         {
                                                             id = Model.CategoryId
                                                         }).ToHtmlString());
                                                     }).SelectedIndex(0).Render();
}
@Html.Telerik().Window().Name("windowAddProperty").Modal(true).Title("Add Property").Width(400).Height(200).Content("<iframe class=\"dialog\" src=\"\"></iframe>").Draggable(true).Visible(false)
@section css {
    <style type="text/css">
        .dialog
        {
            border: none;
            height: 95%;
            outline: none;
            width: 100%;
        }
        
        .tag-option
        {
            padding: 5px 10px;
        }
    </style>
}
@section script
{
    <script type="text/javascript">

        $(document).ready(function() {
            var ids = $('#Ids').val().split(',');
            for (var i = 0; i < ids.length; i++) {
                $('#tag_' + ids[i]).attr('checked', 'checked');
            }
        });

        function addProperty() {
            var window = $('#windowAddProperty').data('tWindow');
            window.center();
            $('.dialog').attr('src', '@Url.Action("AddProperty", new
                                 {
                                     id = Model.CategoryId
                                 })');
            window.open();
        }

        function closePopup(obj) {
            var window = $('#windowAddProperty').data('tWindow');
            window.close();
            if (obj) {
                $("#grid").data("tGrid").ajaxRequest();
            }
        }

        function deleteProperty(id) {
            if (confirm("Do you want to delete?"))
                $.post('@Url.Action("DeleteProperty", "Category")', { id: id }, function() {
                    $("#grid").data("tGrid").ajaxRequest();
                });
        }

        function updateTag() {
            var obj = $('.tag');
            var ids = [];
            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    ids.push($(obj[i]).attr('value'));
                }
            }
            $.post('@Url.Action("AddTag")', { id: @Model.CategoryId, ids: ids.toString() }, function(data) {
                alert("Update Successfully");
            });
        }

    </script>
}
